package com.landleaf.smarthome.model;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.ToMany;

import java.io.Serializable;
import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;

/**
 * When I wrote this, only God and I understood what I was doing
 * Now, God only knows
 * Created by 海航
 * 2020/9/1
 * 功能描述:
 */
@Entity
public class RoomModel implements Serializable {

    private static final long serialVersionUID = -8437593358448407086L;
    /**
     * roomName : 测试房间2
     * roomType : 1
     * sortNo : 2
     * devices : [{"deviceSn":"3","deviceName":"测试设备3","port":" ","sortNo":3,"productCode":"5-001"},{"deviceSn":"4 ","deviceName":"测试设备4","port":" ","sortNo":4,"productCode":"5-001"}]
     */
    @Id(autoincrement = true)
    private Long id = null;
    private String roomName;
    private int roomType;
    private int sortNo;
    private long floorId;
    @ToMany(referencedJoinProperty = "roomId")
    private List<DeviceModel> devices;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 2009295209)
    private transient RoomModelDao myDao;
    @Generated(hash = 879773353)
    public RoomModel(Long id, String roomName, int roomType, int sortNo, long floorId) {
        this.id = id;
        this.roomName = roomName;
        this.roomType = roomType;
        this.sortNo = sortNo;
        this.floorId = floorId;
    }
    @Generated(hash = 486491942)
    public RoomModel() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getRoomName() {
        return this.roomName;
    }
    public void setRoomName(String roomName) {
        this.roomName = roomName;
    }
    public int getRoomType() {
        return this.roomType;
    }
    public void setRoomType(int roomType) {
        this.roomType = roomType;
    }
    public int getSortNo() {
        return this.sortNo;
    }
    public void setSortNo(int sortNo) {
        this.sortNo = sortNo;
    }
    public long getFloorId() {
        return this.floorId;
    }
    public void setFloorId(long floorId) {
        this.floorId = floorId;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1645560393)
    public List<DeviceModel> getDevices() {
        if (devices == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DeviceModelDao targetDao = daoSession.getDeviceModelDao();
            List<DeviceModel> devicesNew = targetDao._queryRoomModel_Devices(id);
            synchronized (this) {
                if (devices == null) {
                    devices = devicesNew;
                }
            }
        }
        return devices;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1428662284)
    public synchronized void resetDevices() {
        devices = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 531565243)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getRoomModelDao() : null;
    }

}
